package com.yx.musicplayer.ui.adapter;

import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.yx.musicplayer.R;

import java.util.List;

/**
 * Created by yx on 2017/11/1 0001.
 */

public class MusicAdapter extends BaseMultiItemQuickAdapter<MusicItem, BaseViewHolder> {

    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
    public MusicAdapter(List<MusicItem> data) {
        super(data);
        addItemType(MusicItem.SPECIAL_SONG, R.layout.ui_special_song_item);
        addItemType(MusicItem.SINGER, R.layout.ui_music_other_item);
        addItemType(MusicItem.ALBUM, R.layout.ui_music_other_item);
        addItemType(MusicItem.FOLDER, R.layout.ui_music_other_item);
    }

    @Override
    protected void convert(BaseViewHolder helper, MusicItem item) {
        switch (item.getItemType()) {
            case MusicItem.SPECIAL_SONG:
                helper.setText(R.id.tv_song_name, item.getSongs().title);
                helper.setText(R.id.tv_singer_name, item.getSongs().artistName + "—" + item.getSongs().albumName);
                break;
            case MusicItem.SINGER:
//                ((BaseActivity)mContext).request(RetrofitUtil.create(LastFmService.class).getArtistInfo(item.getArtist().name),new MySubscriber<String>() {
//                    @Override
//                    public void onSuccess(String s) {
//
//                    }
//
//                    @Override
//                    public void onFinal() {
//
//                    }
//                });

                Glide.with(mContext).load("https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=2539922263,2810970709&fm=200&gp=0.jpg").into((ImageView) helper.getView(R.id.iv_image));
                helper.setText(R.id.tv_singer_name, item.getArtist().name);
                helper.setText(R.id.tv_num, item.getArtist().songCount + "首");
                break;
            case MusicItem.ALBUM:
                Glide.with(mContext).load("https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=2539922263,2810970709&fm=200&gp=0.jpg").into((ImageView) helper.getView(R.id.iv_image));
                helper.setText(R.id.tv_singer_name, item.getAlbum().title);
                helper.setText(R.id.tv_num, item.getAlbum().songCount + "首  " + item.getAlbum().artistName);
                break;
            case MusicItem.FOLDER:
                ((ImageView) helper.getView(R.id.iv_image)).setImageResource(R.drawable.vector_drawable_file_logo);
                helper.setText(R.id.tv_singer_name, item.getFolderInfo().folderName);
                helper.setText(R.id.tv_num, item.getFolderInfo().songCount + "首  " + item.getFolderInfo().folderPath);
                break;
            default:
                break;
        }

    }
}
